<?php

class PeopleController extends Controller
{
	public function actionIndex()
	{
		$pid=Yii::app()->request->getParam('pid');
		//List toan bo thanh vien cua Du an 
		$UserInProjectList= ProjectUser::model()->findAllByAttributes(array('project_user_project_id'=>$pid));
		foreach($UserInProjectList as $item){
			$UserList[] = $item->projectUserUser;
		}
		$this->render('index',array('UserList'=>$UserList,'pid'=>$pid));
	}

	// -----------------------------------------------------------
	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
	public function actionUserDetail()
	{
		$pid= Yii::app()->request->getParam('pid');
		$uid= Yii::app()->request->getParam('uid');
		$User= User::model()->findByPk($uid);
		
		$model=new User();
		 // edit avatar
	
		
		//edit user info
		if(isset($_POST['User'])){
			$User->attributes= $_POST['User'];
			$image = CUploadedFile::getInstance($User, 'image');

			if(is_object($image)){
				
				$image->saveAs(Yii::app()->basePath.'/images/avatar/'.$image->name);
				$User->user_avatar=Yii::app()->request->baseUrl."/protected/images/avatar/".$image->name;
				if($User->save()){
				 Yii::app()->user->setFlash('success','Update avatar success');
				}
			}
			if(!strcmp($User->user_password,'123456')){
				User::model()->updateByPk($uid,array('user_name'=>$User->user_name,
				'user_email'=>$User->user_email,'user_mobile_phone'=>$User->user_mobile_phone));
			}
			else {
			if($User->save()){
					 Yii::log("Chung : save thanh cong ");
			 		 Yii::app()->user->setFlash('success','Edit success !');
				}
			}
		}
		$this->render('userDetail',array('User'=>$User,'model'=>$model));
	}
	
}